<?php

/*
* Viet Thanh captcha version 1
*/

class Ttcaptcha {
	// this will create two words and return their combined word
	public function create_text() {
		$ran_str = md5(microtime());
		$first = substr($ran_str, 0, 2);
		$second = substr($ran_str, 5, 3);
		//$ran_str = $first . ' ' . $second ;
		return $first . ' ' . $second;
	}
	
	// this will create captcha image
	public function create_image_captcha($text, $font, $background) {
		//create captcha image based on a image background
		$captcha_img = imagecreatefromjpeg($background);
		
		//$white = imagecolorallocate($captcha_img, 255, 255, 255);
		$grey = imagecolorallocate($captcha_img, 128, 128, 128);
		$black = imagecolorallocate($captcha_img, 0, 0, 0);
		
		//crate shadow text and real text
		$shadow = rand(-10, 10);
		$real = rand(-10, 10);
		
		//create text color
		$color = imagecolorallocate($captcha_img, 0, 50, 160);
		
		//make shadow text
		imagettftext($captcha_img, 15, $shadow, 11, 21, $grey, $font, $text);
		
		//make real text
		imagettftext($captcha_img, 15, $real, 11, 21, $color, $font, $text);
		
		//show captcha image
		header("Content-type: image/jpeg");
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
		header("Cache-Control: no-store, no-cache, must-revalidate"); 
		header("Cache-Control: post-check=0, pre-check=0", false);
		header("Pragma: no-cache");
		imagejpeg($captcha_img);
		imagedestroy($captcha_img);
	}
}
?>